//
//  ModelListViewController.m
//  ElectronicSandTable
//
//  Created by 苏晓凯 on 2017/6/16.
//  Copyright © 2017年 苏晓凯. All rights reserved.
//

#import "ModelListViewController.h"
#import "ShowModelViewController.h"
#import "ViewController.h"

@interface ModelListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *modelListTableView;
@property (nonatomic, strong)NSMutableArray *contentArr;
@property (nonatomic, strong)NSMutableArray *modelNameArr;
@end

@implementation ModelListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 在目录中寻找文件列表
    NSFileManager * fileManager = [NSFileManager defaultManager];
    NSError * error;
    NSArray * fileList = [fileManager contentsOfDirectoryAtPath:[[NSBundle mainBundle] bundlePath] error:&error];
    //文件数组
    self.contentArr = [[NSMutableArray alloc] init];
    [fileList enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.pathExtension isEqualToString:@"3gd"]) {
            [self.contentArr addObject:obj];
        }
    }];
    NSLog(@"%@",self.contentArr);
    self.modelNameArr = [[NSMutableArray alloc]init];
    [self.modelNameArr addObject:@"南洺河特大桥"];
    [self.modelNameArr addObject:@"北洺河特大桥"];
    [self.modelNameArr addObject:@"顿井互通"];
    [self.modelNameArr addObject:@"冶陶互通"];
    [self.modelNameArr addObject:@"东坡隧道"];
    NSLog(@"%@",self.modelNameArr);
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];

}

#pragma mark - UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.modelNameArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"modelCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"modelCell"];
    }
    cell.textLabel.text = self.modelNameArr[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
//    ViewController *vc = [[ViewController alloc] init];
//    [self presentViewController:vc animated:YES completion:nil];
    
//    [self.navigationController pushViewController:vc animated:YES];
    
    
    ShowModelViewController *modelVc = [[ShowModelViewController alloc]init];
    modelVc.fileName = [NSString stringWithFormat:@"00%li.3gd",(long)indexPath.row];// @"8474619-02af-43e9-bfbd-3affaeb96afa.3gd";//self.contentArr[indexPath.row];

    modelVc.index = indexPath.row;
//    modelVc.fileName = @"8474619-02af-43e9-bfbd-3affaeb96afa.3gd";
//    modelVc.fileName = @"395d954a-72cc-413e-9d45-7836546cd51a.3gd";
    
    [self presentViewController:modelVc animated:YES completion:nil];
    
//    [self.navigationController pushViewController:modelVc animated:YES];

}

//支持旋转
-(BOOL)shouldAutorotate{
    return YES;
}

//支持的方向 因为界面A我们只需要支持竖屏
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
@end
